#coding=utf-8
import unittest
from selenium import webdriver
from appium import webdriver
from time import sleep
from nav_plugin_op import nav_plugin_factory
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.support.ui import WebDriverWait
import os
from Public import BasePage
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from Public import BaseConstant

navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
basicAction = BasicAction()
Reportevaluationn_Paramter_instances = BaseConstant.Reportevaluationn_Paramter
# nav_name = "工作"
# plugin_name = "案件处置"
nav_name = ["导航栏工作",'xpath',"//android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RadioButton"]
plugin_name = ["插件列表-考评上报",'name','考评上报']
report_desc_name = "主动上报"

class report_evaluation_factory():

	def open_report_evaluation_plug(self,driver,file_path):
		try:
			element_oprate_instance.element_click(nav_name,file_path)
			driver.swipe(400,1000,400,50,1200)
			sleep(2)
			driver.swipe(400,800,400,50,1200)
			element_oprate_instance.element_click(plugin_name,file_path)
			driver.implicitly_wait(15)
			if element_oprate_instance.element_display_commit(Reportevaluationn_Paramter_instances.evaluation_task_name, file_path):
				print("open_report_evaluation success.....")
				element_oprate_instance.element_save_pic(file_path, 'open_report_evaluation_successful')
			else:
				print("open_report_evaluation failed.....")

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'open_report_evaluation_fail')
			raise

	def add_examination_report(self,driver,file_path):
		try:
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.action_add_id, file_path)
			driver.implicitly_wait(15)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.event_type_id, file_path)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.event_type_name, file_path)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.main_type_id, file_path)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.main_type_name, file_path)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.sub_type_id, file_path)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.sub_type_name, file_path)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.location_desc_id, file_path)
			sleep(2)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.location_desc_name, file_path)
			driver.implicitly_wait(15)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.confirm_name, file_path)
			sleep(1)
			#添加描述信息
			# element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.report_desc_id, file_path)
			element_oprate_instance.element_send_keys(Reportevaluationn_Paramter_instances.report_desc_id,report_desc_name.decode("utf-8"), file_path)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.media_view_id, file_path)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.photoadd_id, file_path)
			sleep(2)
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.first_photo_select_button, file_path)
			#相册界面点击确定按钮
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.select_id, file_path)
			#点击确认上报按钮
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.report_btn_id, file_path)
			sleep(5)
			element_oprate_instance.element_save_pic(file_path, 'add_examination_report_successful')
			element_oprate_instance.element_click(Reportevaluationn_Paramter_instances.confirm_name, file_path)

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'add_examination_report_fail')
			raise

if __name__ == '__main__':
	unittest.main()